import org.anderson.FitJPA.ExtendingClass
import org.easyspec.EasySpec
import org.easyspec.Context
import org.easyspec.Behavior

/**
 * Created by IntelliJ IDEA.
 * User: HP_Administrator
 * Date: Sep 6, 2008
 * Time: 2:32:06 AM
 * To change this template use File | Settings | File Templates.
 */
class EntityParser_when_input_specifies_columns_Test extends GroovyTestCase {

    def instance

    @Context('when the input data specifies columns rather than fields')
    public void setUp() {
        def parser = new EntityParser()
            def data = new MapBeanData(['A_STRING':'12345678901234', 'AN_INTEGER':'1234', 'A_DOUBLE':'333', 'A_DATE':'2008-10-31'])

        instance = parser.parse(ExtendingClass.class, data)
    }

    @Behavior
    public void test_should_return_an_instance_of_the_specified_type() {
        assertEquals ExtendingClass.class, instance.class
    }

    @Behavior
    public void test_should_return_an_instance_with_String_set() {
        assertEquals '12345678901234', instance.aString
    }

    @Behavior
    public void test_should_return_an_instance_with_Integer_set() {
        assertEquals 1234, instance.anInteger
    }

    @Behavior
    public void test_should_return_an_instance_with_Double_set() {
        assertEquals 333l, instance.aDouble
    }

    @Behavior
    public void test_should_return_an_instance_with_Date_set() {
        Date actual = instance.aDate
        assertEquals 108, actual.year
        assertEquals 9, actual.month
        assertEquals 31, actual.date
    }

}